package com.atguign.gulimall.ware.service.impl;

import com.atguign.gulimall.ware.dao.WareInfoDao;
import com.atguign.gulimall.ware.entity.WareInfoEntity;
import com.atguign.gulimall.ware.service.WareInfoService;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.Query;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Map;


@Service("wareInfoService")
public class WareInfoServiceImpl extends ServiceImpl<WareInfoDao, WareInfoEntity> implements WareInfoService {
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String key = (String) params.get("key");
        LambdaQueryWrapper<WareInfoEntity> wareInfoEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();

        if(StringUtils.hasText(key)){
            wareInfoEntityLambdaQueryWrapper.and(w->{
                w.eq(WareInfoEntity::getId,key);
                w.like(WareInfoEntity::getName,key);
            });
        }
        IPage<WareInfoEntity> page = this.page(
                new Query<WareInfoEntity>().getPage(params),
                wareInfoEntityLambdaQueryWrapper
        );

        return new PageUtils(page);
    }

}